home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / mpp.exe / DEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-10-07  |  13KB  |  460 lines

  1. /* -------------------------------------------------------------------- */
  2. /* Mouse++ Version 4.0             demo.cpp            Revised 10/05/92 */
  3. /*                                                                      */
  4. /* General mouse class for Turbo C++/Borland C++.                       */
  5. /* Copyright 1991, 1992 by Carl W. Moreland                             */
  6. /* -------------------------------------------------------------------- */
  7. /* Demonstration of Mouse++ in text mode and graphics mode.             */
  8. /* -------------------------------------------------------------------- */
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <graphics.h>
  15. #include "mouse.h"
  16. #include "cursor.h"
  17.  
  18. void textdemo(void);
  19. int  textscreen(void);
  20. void alttextscreen(void);
  21. void nexttdemo(char *);
  22. void graphicdemo(void);
  23. int  graphicscreen(void);
  24. void nextgdemo(char *);
  25.  
  26. int maxx, maxy;
  27. int text_width, text_height;
  28. struct text_info t_info;
  29. int done = 0;
  30.  
  31. MouseEventHandler myHandler(MB_PRESSED|MB_RELEASED, MouseHandler);
  32.  
  33. main()
  34. {
  35.   if(mouse.Exists())                // check for mouse
  36.   {
  37.     mouse.InstallHandler(0xFF);        // install event handler
  38.     mouse.Enable();            // enable mouse
  39.     textdemo();                // run text mode demo
  40.  
  41.     mouse.SetRepeatRate(CENTERBUTTON,    // set the center button to repeat
  42.                         500, 200);
  43.     graphicdemo();            // run graphics mode demo
  44.     return(0);                // normal termination
  45.   }
  46.   return(1);                // abnormal termination
  47. }
  48.  
  49. /* ----- text mode demo ----------------------------------------------- */
  50.  
  51. void textdemo()                // main routine for text mode demo
  52. {
  53.   textmode(C80);            // 80x25 color text mode
  54.   if(textscreen() == 0)            // draw the screen
  55.   {
  56.     alttextscreen();            // draw the alt screen
  57.     textcolor(13);
  58.     gotoxy(1,3);
  59.  
  60.     if(mouse.Info.type == 1) cprintf(" Bus mouse found\n");
  61.     if(mouse.Info.type == 2) cprintf(" Serial mouse found\n");
  62.     if(mouse.Info.type == 3) cprintf(" InPort mouse found\n");
  63.     if(mouse.Info.type == 4) cprintf(" PS/2 mouse found\n");
  64.     if(mouse.Info.type == 5) cprintf(" HP mouse found\n");
  65.     gotoxy(1,4);
  66.     cprintf(" Software version is %d.%d\n", (int)mouse.Info.majorvers,
  67.               (int)mouse.Info.minorvers);
  68.  
  69.     mouse.yLimit(0, 199);        // set y limit
  70.     mouse.Show();            // initial turn-on
  71.  
  72.     if(!done) { mouse.SetCursor(tdef); nexttdemo("     Default Cursor      "); }
  73.     if(!done) { mouse.SetCursor(txt1); nexttdemo(" 0000h 0E0Fh Soft Cursor "); }
  74.     if(!done) { mouse.SetCursor(txt2); nexttdemo(" 7000h 0E0Fh Soft Cursor "); }
  75.     if(!done) { mouse.SetCursor(txt3); nexttdemo(" 7F00h FF0Fh Soft Cursor "); }
  76.     mouse.xLimit(16, 623);
  77.     if(!done) { mouse.SetCursor(txt4); nexttdemo(" 00FFh 0FD4h Soft Cursor "); }
  78.  
  79.     mouse.Hide();
  80.     textmode(C4350);            // 43/50 line mode
  81.     _setcursortype(_NOCURSOR);        // turn the hardware cursor off
  82.     mouse.xLimit(0, 639);        // set x limit
  83.     gettextinfo(&t_info);
  84.     if(t_info.screenheight == 43)
  85.       mouse.yLimit(0, 349);        // set y limit to EGA 43 line
  86.     else
  87.       mouse.yLimit(0, 399);        // set y limit to VGA 50 line
  88.     mouse.Show();
  89.     if(!done) { mouse.SetCursor(txt4); nexttdemo("     Default Cursor      "); }
  90.   }
  91. }
  92.  
  93. int textscreen(void)            // draws screen for demo
  94. {
  95.   register int i, j;
  96.   char far *video = (char far *)MK_FP(0xB800, 0x0000);
  97.  
  98.   _setcursortype(_NOCURSOR);        // turn the hardware cursor off
  99.  
  100.   for(i=0; i<50; i++)            // draw the text screen background
  101.   {
  102.     for(j=0; j<80; j++)
  103.     {
  104.       *video++ = 0xDB+2*(j/10);        // write the character to video memory
  105.       *video++ = 16*(j/10)+j/10+1;    // write the color
  106.     }
  107.   }
  108.  
  109.   gotoxy(27,1);
  110.   textattr(4);
  111.   cprintf(" Text Mode Demonstration ");
  112.  
  113.   textattr(LIGHTGRAY);
  114.   for(i=5; i<13; i++)
  115.   {
  116.     gotoxy(5, i);
  117.     cprintf("██████████");
  118.   }
  119.   textattr(DARKGRAY);
  120.   for(i=6; i<8; i++)
  121.   {
  122.     gotoxy(6, i);
  123.     cprintf("██");
  124.     gotoxy(9, i);
  125.     cprintf("██");
  126.     gotoxy(12, i);
  127.     cprintf("██");
  128.   }
  129.   textattr(WHITE);
  130.   gotoxy(6,9);
  131.   cprintf("Position");
  132.  
  133.   textattr(LIGHTBLUE);
  134.   gotoxy(37,22); cprintf("╔══════╗");
  135.   gotoxy(37,23); cprintf("║ Next ║");
  136.   gotoxy(37,24); cprintf("╚══════╝");
  137.  
  138.   return(0);
  139. }
  140.  
  141. void alttextscreen(void)        // copies page0 to page2
  142. {
  143.   register int i, j;
  144.  
  145.   char far *page0 = (char far *)MK_FP(0xB800, 0x0000);
  146.   char far *page2 = (char far *)MK_FP(0xBA00, 0x0000);
  147.  
  148.   for(i=0; i<50; i++)            // draw the text screen background
  149.   {
  150.     for(j=0; j<80; j++)
  151.     {
  152.       *page2++ = *page0++;        // copy the characters
  153.       *page2++ = (*page0++ << 1);    // copy the color*2
  154.     }
  155.   }
  156. }
  157.  
  158. void nexttdemo(char *str)
  159. {
  160.   static int page = 0;
  161.  
  162.   textattr(4);
  163.   gotoxy(27,2);
  164.   cprintf(str);                // print title
  165.   textattr(13);
  166.   for(;;)
  167.   {
  168.     mouse.GetEvent();
  169.     textattr(WHITE);
  170.     gotoxy(6,10);
  171.     cprintf(" %2d  %2d ", mouse.xPos() >> 3, mouse.yPos() >> 3);
  172.  
  173.     (mouse.LB_Dn()) ? textattr(RED) :
  174.                       textattr(DARKGRAY);
  175.     gotoxy(6,6);
  176.     cprintf("██");
  177.     gotoxy(6,7);
  178.     cprintf("██");
  179.     (mouse.CB_Dn()) ? textattr(RED) :
  180.                       textattr(DARKGRAY);
  181.     gotoxy(9,6);
  182.     cprintf("██");
  183.     gotoxy(9,7);
  184.     cprintf("██");
  185.  
  186.     (mouse.RB_Dn()) ? textattr(RED) :
  187.                       textattr(DARKGRAY);
  188.     gotoxy(12,6);
  189.     cprintf("██");
  190.     gotoxy(12,7);
  191.     cprintf("██");
  192.  
  193.     if(mouse.Released(LEFTBUTTON))    // check for LB release
  194.       if(mouse.InBox(36*8, 21*8, 43*8, 23*8))
  195.         return;
  196.  
  197.     if(mouse.DoubleClick(RIGHTBUTTON))
  198.     {
  199.       mouse.ClearClick(RIGHTBUTTON);
  200.       return;
  201.     }
  202.  
  203.     if(mouse.DoubleClick(CENTERBUTTON))
  204.     {
  205.       mouse.Disable();
  206.       textattr(4);
  207.       gotoxy(1,1);
  208.       cprintf("Hit any key...");
  209.       while(!getch());
  210.       textattr(DARKGRAY);
  211.       gotoxy(1,1);
  212.       cprintf("██████████████");
  213.       mouse.Enable();
  214.       mouse.Show();
  215.     }
  216.  
  217.     if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & CTRL_PRESSED))
  218.     {
  219.       done = 1;
  220.       return;
  221.     }
  222.  
  223.     if(mouse.Pressed(LEFTBUTTON) && (mouse.Button() & SHIFT_PRESSED))
  224.     {
  225.       mouse.Hide();
  226.       page = (page == 0 ? 2 : 0);
  227.  
  228.       _AH = 0x05;
  229.       _AL = page;
  230.       geninterrupt(0x10);
  231.  
  232.       mouse.SetVideoPage(page);
  233.       mouse.Show();
  234.     }
  235.   }
  236. }
  237.  
  238. /* ----- graphics mode demo ------------------------------------------- */
  239.  
  240. void graphicdemo()            // main routine for graphics demo
  241. {
  242.   mouse.Hide();
  243.   if(graphicscreen() == 0)        // draw the screen
  244.   {
  245.     done = 0;
  246.     mouse.yLimit(0, maxy);        // set y limit (EGA=350, VGA=480)
  247.     mouse.Move(maxx/2, maxy/2);
  248.     mouse.Show();            // initial turn on
  249.  
  250.     mouse.SetSpeedThreshold(32);
  251.     mouse.MickToPix(8, 8);
  252.     if(!done) { mouse.SetCursor(gcDefault);   nextgdemo(" Default "); }
  253.     if(!done) { mouse.SetCursor(gcCross);     nextgdemo("  Cross  "); }
  254.     if(!done) { mouse.SetCursor(gcCheck);     nextgdemo("  Check  "); }
  255.     if(!done) { mouse.SetCursor(gcPlus);      nextgdemo("  Plus   "); }
  256.     if(!done) { mouse.SetCursor(gcGun);       nextgdemo("   Gun   "); }
  257.     if(!done) { mouse.SetCursor(gcHand);      nextgdemo("  Hand   "); }
  258.     if(!done) { mouse.SetCursor(gcHourglass); nextgdemo("Hourglass"); }
  259.     if(!done) { mouse.SetCursor(gcBullseye);  nextgdemo(" Bullseye"); }
  260.  
  261.     mouse.MickToPix(4, 4);
  262.     if(!done) { mouse.SetCursor(gcIbeam);     nextgdemo("  IBeam  "); }
  263.  
  264.     mouse.MickToPix(2, 2);
  265.     if(!done) { mouse.SetCursor(gcJet);       nextgdemo("   Jet   "); }
  266.  
  267.     mouse.MickToPix(16, 16);
  268.     mouse.Move(maxx/2, maxy/2);
  269.     if(!done) { mouse.SetCursor(gcFace);      nextgdemo("  Face   "); }
  270.  
  271.     if(!done) { mouse.SetCursor(cgcMousepp);  nextgdemo("cMousepp "); }
  272.  
  273.     mouse.InstallHandler(myHandler);    // turn off the motion counter
  274.  
  275.     if(!done) { mouse.SetCursor(gcDefault);   nextgdemo(" Default "); }
  276.     closegraph();
  277.   }
  278. }
  279.  
  280. int graphicscreen()
  281. {
  282.   int x, y;
  283.   int driver = EGA, mode = EGAHI;
  284.  
  285.   initgraph(&driver, &mode, "");
  286.   if(graphresult() == grOk)
  287.   {
  288.     maxx = getma